package at.jku.se.fastsell.db4o.transactions;

import at.jku.se.fastsell.db4o.Database;
import at.jku.se.fastsell.db4o.DatabaseException;

import com.db4o.ObjectContainer;

/**
 * Abstract base class for database transactions
 *
 * @param <T> - Return value of transaction
 */
public abstract class Transaction<T> {
	
	protected ObjectContainer db = Database.getDb();
	
	public abstract T run() throws DatabaseException;
	
	public void rollback() {
		db.rollback();
	}
	
	public void commit() {
		db.commit();
	}
	
	public void close() {
		db.close();
	}
	
	@Override
	public String toString() {
		return this.getClass().getName();
	}

}
